package com.leyou.mall.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.leyou.common.pojo.R;
import com.leyou.mall.data.entity.MallGoodsPicture;
import com.leyou.mall.service.MallGoodsPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xhh
 * @since 2022-07-04
 */
@RestController
@RequestMapping("/leyou.mall/mall-goods-picture")
public class MallGoodsPictureController {
    @Autowired
    private MallGoodsPictureService mallGoodsPictureService;
    /**
    * todo 获取图片
    * @param id
    * @return com.leyou.common.pojo.R
    * @author xhh
    * @data 2022/7/13 19:53
    * @deprecated 
    */
    @RequestMapping(value = "/getPhoneListByGoodsId",method = RequestMethod.POST)
    public R getPhoneListByGoodsId(@RequestParam("goodsId")Integer id) {
        LambdaQueryWrapper<MallGoodsPicture> queryWrapper=new LambdaQueryWrapper();
        queryWrapper.eq(MallGoodsPicture::getGoodsId,id);
        queryWrapper.select(MallGoodsPicture::getUrl);
        queryWrapper.orderByDesc(MallGoodsPicture::getMainPic);
        List<MallGoodsPicture> list = mallGoodsPictureService.list(queryWrapper);
        String[] urls=new String[list.size()];
        int i=0;
        for (MallGoodsPicture mallGoodsPicture : list) {
            urls[i++]=mallGoodsPicture.getUrl();
        }
        return R.ok().data("list",urls);
    }
}

